#include <REGX52.H>
#include "TIMER0.h"
#include "NIXIE.h"
#include "Delay.h"
#define RIGHT 0
#define LEFT 1
static char LEDPos,Num,Direction;
static unsigned int T0Count;


void main()
{
	LEDPos=0;
	Num=0;
	Timer0Init();
	
	while(1)
	{
		if(P3_1==0)
		{
			Delay(20);
			while(P3_1==0)
			Delay(20);
			Direction=RIGHT;
		}
		if(P3_0==0)
		{
			Delay(20);
			while(P3_0==0)
			Delay(20);
			Direction=LEFT;
		}
		Nixie(LEDPos+1,Num);
	}
}

//定时器中断函数模板
void Timer0_Routine() interrupt 1
{	
	TL0 = 0x66;		//设置定时初值
	TH0 = 0xFC;		//设置定时初值
	
	T0Count++;
	if(T0Count>=500)//500ms变换一次
	{	
		T0Count=0;	
		if(Direction==RIGHT){LEDPos++;Num++;Num%=10;}
		if(Direction==LEFT)
		{
			LEDPos--;Num--;
			if(Num<0){Num=9;}
			if(LEDPos<0){LEDPos=7;}
		}		
		//Num++;
		
		
		//LEDPos++;
		LEDPos=(LEDPos%8);		
	}
//	LEDPos++;
//	if(LEDPos>=8000)
//	{	
//		LEDPos=0;		
//	}
}
